package com.Service;

import cn.hutool.core.util.NumberUtil;
import com.Bean.Good;
import com.Bean.PurchaseOrder;
import com.Bean.SealOrder;
import com.Common.CodeMsg;
import com.Common.PageInfo;
import com.Common.Result;
import com.Dao.PurchaseOrderDao;
import com.Dao.SealOrderDao;
import com.Service.impl.GoodServiceImpl;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/5/6 20:47
 */
public class purchaseOrderService {
    PurchaseOrderDao purchaseOrderDao = new PurchaseOrderDao();
    public Result queryPage(Map<String, Object> params, String page, String limit) {
        Integer pageNo =  NumberUtil.isNumber(page)?Integer.parseInt(page):1;
        Integer pageSize =  NumberUtil.isNumber(limit)?Integer.parseInt(limit):10;
        PageInfo<PurchaseOrder> pageInfo = purchaseOrderDao.selectPage(params, pageNo, pageSize);
        return new Result(pageInfo);
    }

    public Result deleteOrder(String... ids) {
        boolean flag = purchaseOrderDao.batchDelete(ids);
        return flag?new Result():new Result(CodeMsg.GOOD_DELETE_ERROR);
    }

    public Result addOrder(Integer goodID, Integer userID, String goodName, Integer number, String userName, BigDecimal unitPrice){
        boolean add = purchaseOrderDao.add(goodID, userID, goodName, number, userName, unitPrice);
        if (add){
            return new Result();
        }
        return new Result(CodeMsg.ORDER_ADD_ERROR);
    }
    @Test
    public void test(){
        purchaseOrderService purchaseOrderService = new purchaseOrderService();
        Result result = purchaseOrderService.addOrder(5, 1, "钢笔", 1, "admin", new BigDecimal(13.5));
        System.out.println(result.getCode());
        System.out.println(result.getCode());
    }
}
